<?php
// 房间管理
class RoomAction extends CommonAction {
    function _filter(&$map) {
        $key = trim($_REQUEST['keywords']);
         if(!empty($key)) {
             $map['room_no'] = array('like',"%".$key."%");
             $map['note'] = array('like',"%".$key."%");
              $house_id = M('House')->where("name like '%".$key."%'")->field('id')->findAll();
             $houses = array();
             foreach ($house_id as $k1 => $value) {
                 $houses[$k1] = $value['id'];
             }
             $house_id = implode(",", $houses);
             if(!empty($house_id)) {
                 $map['house_id'] = array('in',$house_id);
             }
             $map['_logic'] = "or";
         }
    }

    function _before_add(){
        $this ->assign('hotel',M('Hotel')->where('status = 1')->field('name,id')->findAll());
        $this->assign('house',M('House')->where('status=1')->findAll());
    }

     function _before_edit(){
        $this ->assign('hotel',M('Hotel')->where('status = 1')->field('name,id')->findAll());
        $this->assign('house',M('House')->where('status=1')->findAll());
        $this->assign('availables',M('Room_available')->where('room_id = '.$_GET['id'])->findAll() );
    }

}
?>